<?php
/**
 * 收钱吧退款接口
 */

namespace App\Services\PosApi;

use App\Models\RefundDetail as RefundDetailModel;

class CashRefund
{
    public $paymentName = '现金';
    public $paymentCode = 'cash';

    public function handle($params,$payInfo,$money)
    {
        $refund = RefundDetailModel::where('order_no',$params['order_no'])->where('refund_no',$params['refund_no'])->where('refund_platform',$this->paymentCode)->first();
        if(!$refund){
            $refund = new RefundDetailModel();
            $refund->refunds_id = $params['refunds_id'];
            $refund->order_no = $params['order_no'];
            $refund->refund_no = $params['refund_no'];
            $refund->refund_amount = $money;
            $refund->refund_platform = $this->paymentCode;

            $refund->save();
        }

        //更新支付状态
        //现金退款这里默认退款成功
        if(true){
            $refund->status = 1;
        }else{
            $refund->status = 2;
            //$refund->fail_memo = '失败原因';
        }
        $refund->save();
        return $refund->toArray();
    }

}